<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <style>
        .aui-bar-nav {
            background-color: #FFF;
            color: #000;
            position: fixed;
        }
        .aui-content {
            margin-top: 2.25rem;
            position: relative;
        }

        .aui-bar-nav .aui-iconfont {
            color: #000!important;
            font-weight: bold;
        }

        .money_ti .aui-list .aui-list-item:first-child input {
            position: relative;
            padding: 0;
            padding-right: 1%;
            line-height: 2rem;
            vertical-align: middle;
        }
        .money_ti .aui-list .aui-list-item input{
          line-height: 2rem;
        }

        .money_ti .aui-list .aui-list-item:first-child .aui-list-item-input {
            display: flex;
            align-items: center;
        }

        .money_ti .aui-list .aui-list-item:first-child .aui-list-item-input span {
            display: block;
            width: 4rem;
            line-height: 2.6rem;
            color: #FE2525;
            font-weight: bold;
        }
    </style>
</head>

<body>
    <header id="header" class="aui-bar aui-bar-nav">
        <a class="aui-pull-left aui-btn" tapmode onclick="comeBack()">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title">提现</div>
    </header>
    <div id="aui-content" class="aui-content money_ti">
        <div class="top-box">
            <p>我的余额</p>
            <h2 id="mymoney">0.00</h2>
        </div>
        <div class="tit">选择提现金额</div>
        <div class="cen-box">
            <span class="active" data-num="10">10元</span>
            <span data-num="20">20元</span>
            <span data-num="50">50元</span>
            <span data-num="100">100元</span>
            <span data-num="200">200元</span>
            <span data-num="300">300元</span>
        </div>
        <div class="bottom-box">
            <ul class="aui-list aui-form-list">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">所属金额</div>
                        <div class="aui-list-item-input">
                            <input type="number" id="moneyNum" value='10'><span>元</span>
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-input">
                            <input type="text" id="cname" readonly="readonly" placeholder="请输入姓名">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-input">
                            <input type="text" id="alipay"  readonly="readonly"  placeholder="请输入支付宝账号">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-input">
                            <input type="text" id="calipay"  readonly="readonly"  placeholder="请确认支付宝账号">
                        </div>
                    </div>
                </li>
            </ul>
            <div id="txmark" class="bottom-bage">  </div>
        <div class="fiex-bott">
              <div class="bottom-btn"><button onclick="tapSubmit(this)" id="loginBtn" type="button">提交</button></div>
        </div>
        <!-- <div>提交</div> -->
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="../script/md5.min.js"></script>
<script type="text/javascript">
    apiready = function() {
        initHeard();
        $api.fixStatusBar($api.byId('aui-content'));
        getPageInit(); //获取金额
        var userInfo = $api.getStorage('user');
        userInfo = JSON.parse(userInfo);
        $("#txmark").html('注：提交申请后24小时之内到账,周末节假日不打款。(支付宝官方 每笔提现收取'+userInfo.tx_fee+'%元手续费）');
        if (userInfo.apply_name) {
            $("#cname").val(userInfo.apply_name);
        }
        if (userInfo.apply_account) {
            $("#alipay").val(userInfo.apply_account);
            $("#calipay").val(userInfo.apply_account);
        }
    };
    //选择金额
    $('.cen-box').on('click', 'span', function() {
        $(this).addClass("active").siblings().removeClass("active");
        var num = $(this).attr("data-num");
        $("#moneyNum").val(num);
    });

    function tapSubmit(that) {
        var cname =   $("#cname").val();
        var alipay =   $("#alipay").val();
        var calipay =   $("#calipay").val();
        var moneyNum =   $("#moneyNum").val();
        var mymoney =   $("#mymoney").text();
         if(cname == ""){
             _msg("请输入姓名");
             return false;
         }else if(alipay == ""){
            _msg("请输入支付宝账号");
            return false;
         }else if(calipay == ""){
            _msg("请确认支付宝账号");
            return false;
         }else if(alipay != calipay){
           _msg("两次输入的账号不同");
           return false;
         }else if(moneyNum == ""){
           _msg("输入的金额不能为空");
           return false;
         }else if(Number(mymoney) < Number(moneyNum) ){
           _msg("余额不足");
           return false;
         }
         _ajax("user/cash",{apply_name:cname,apply_account:calipay,cash_money:Number(moneyNum)}, function(res, err) {
             if (res) {
                 _msg(res.msg);
                 if (res.errCode == 1) {
                   var jsFun = 'getPageInit()';
                   api.execScript({
                       name: "home",
                       script: jsFun
                   });
                   api.execScript({
                       frameName: 'index',
                       name: "root",
                       script: jsFun
                   });
                   setTimeout(function(){
                     comeBack();
                   },1200)
                 } else if (res.errCode == -1) {
                    //  alert("提现失败")
                     openWin('login');
                 }
             } else {
                 _msg("网络错误");
             }
         })

    };
    //获取金额
    function getPageInit() {
      _loading();
        _ajax("index/income", {}, function(res, err) {
            console.log(JSON.stringify(res))
            if (res) {
                if (res.errCode) {
                    var money = Number(res.data.user_money);
                    if (money) {
                        $("#mymoney").html(money.toFixed(2));
                    }
                } else {
                    _msg(res.msg);
                }
            } else {
                _msg("网络错误");
            }
             _loadingCloes();
        })
    };
</script>

</html>
